package com.cloud.item.controller;

import com.cloud.item.client.OrderClient;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

/**
 * @author lscl
 * @version 1.0
 * @intro:
 */
@RestController
@RequestMapping("/demo")
public class DemoController {

    @Autowired
    private OrderClient orderClient;

    @GetMapping("/findOrderById/{orderId}")
    public Map findOrderById(@PathVariable Integer orderId) {

        Map resultMap = orderClient.findById(orderId);

        return resultMap;
    }


    @GetMapping("/findOrderAll")
    public Map findOrderAll() {

        System.out.println(Thread.currentThread().getName());
        Map resultMap = orderClient.findAll();

        return resultMap;
    }


    /**
     * 测试Hystrix接口
     *
     * @param flag
     * @return
     */
    @GetMapping("/testHystrix/{flag}")
    public Map testHystrix(@PathVariable String flag) {

        Map resultMap =orderClient.testHystrix(flag);

        return resultMap;
    }

}
